<?php
namespace Api\Controller;
use Think\Controller;

class BallController extends BaseController {

   private $m = NULL;
   private $md = NULL;
   private $navName = '订单管理';


   public function _initialize(){
   		parent::_initialize();
		$this->m = M('shop');
		$this->md = M('shop_detail');
		
		
   }
    	 	
	/**   聚餐美食-猜你喜欢  liuq
	*
	*/	
  
   public  function slist(){
  
       //$cid = I('cid');//  用户标识  member   id
       $data = $this->m->where('(shop_level_two = 6  OR  shop_level_two = 30)  AND buss_status = 2')->order('id desc')->select();      
  
       foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
              
                 }
                 
             
    returnApiData2('0','成功',$data, $data2,$data3);exit;	     
       
   }
   
      
   public  function  five_order(){  //  5  29
               $order_type  =  I('order_type'); //排序条件  1智能排序   2 离我最近   3 最新发布   4 价格最高  5 价格最低
               $data = $this->m->where('(shop_level_two = 6  OR  shop_level_two = 30)  AND buss_status = 2')->select();
              
     if( $order_type == 1){
         foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                 
                   foreach($data as $v){  
                      $flag[] = $v['add_time'];  
                   }  
                   array_multisort($flag, SORT_ASC, $data); 
                   
               }
               
               
               
    if( $order_type == 3){
                    
         foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                 
                   foreach($data as $v){  
                      $flag[] = $v['add_time'];  
                   }  
                   array_multisort($flag, SORT_DESC, $data); 
                
                }
              
                
                
     if($order_type == 4){
        foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                  foreach($data as $v){  
                         $flag[] = $v['per_consumption'];  
                   }  
                  array_multisort($flag, SORT_DESC, $data); 
        }
        
        
       if($order_type == 5){
        foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                  foreach($data as $v){  
                         $flag[] = $v['per_consumption'];  
                   }  
                  array_multisort($flag, SORT_ASC, $data); 
        }
    
       returnApiData2('0','成功',$data, $data2,$data3);exit;	
               
               
   }

   public function   choice(){//  网咖    网吧    台球    默认值为0   被选中为1
        $internet_bar =  I('internet_bar');///   网咖
        $internet_ba =  I('internet_ba');  //  网吧
        $internet_ball =  I('internet_ball');//    台球
        
        if(!empty($internet_bar) && $internet_bar == 1){
             $where['internet_bar'] = 1;  
        }
      
        if(!empty($internet_ba) && $internet_ba == 2 ){
             $where['internet_ba'] = 1;  
        }
 
        if(!empty($internet_ball) && $internet_ball == 3){
             $where['internet_ball'] = 1 ;  
        }
        
      $data = $this->md->where($where)->order('id desc')->select();
         
 
      foreach ($data as $key => $value) {
           
            $shop_level_two = M('shop')->where("id=".$value['s_id'])->getField('shop_level_two');
            $shop=M('shop')->where("id=".$value['s_id'])->find();
             
            if( $shop_level_two== 6 || $shop_level_two == 30){
                  $string.=$shop['id'].'|';
           
              }
            
         }
         
          $array=explode("|", $string);
          array_pop($array);
          foreach ($array as $key => $value) {
           $data4[$key]['shop_name'] = M('shop')->where('id="'.$value.'"')->getField('shop_name');
              $data4[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('per_consumption');
                $data4[$key]['start_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('start_time'); 
                    $data4[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('stop_time'); 
                      $data4[$key]['address'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('address'); 
                         $data4[$key]['shop_heapic'] = $this->md->where('s_id="'.$value.'"')->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
  
           }
           
            returnApiData2('0','成功',$data4, $data2,$data3);exit;
   }

   
   
}